package com.leetcode.algorithm.y22.m07;

/**
 * 153. 寻找旋转排序数组中的最小值
 * 
 * https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/
 * 
 * @author jie.deng
 *
 */
class Question0153Solution01 {
	
	public int findMin(int[] nums) {
		int len = nums.length;
		if (nums[0] <= nums[len - 1]) {
			// 只有1个元素或者已经是升序排列
			return nums[0];
		}
		int left = 0;
		int right = len - 1;
		while (left < right) {
			// 找第一个小于nums[0]的元素
			int mid = left + ((right - left) >> 1);
			if (nums[mid] < nums[0]) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		return nums[right];
	}
    
}